subjects = {
    'RSRC2001'...
    'RSRC2002'...
    'RSRC2003'...
    'RSRC2004'...
    'RSRC2005'...
    'RSRC2006'...
    'RSRC2007'...
    'RSRC2008'...
    'RSRC2009'...
    'RSRC2010'...
    'RSRC2011'...
    'RSRC2012'...
    'RSRC2014'...
    'RSRC2015'...
    'RSRC2016'...
    'RSRC2017'...
    'RSRC2018'...
    'RSRC2019'...
    'RSRC2020'...
    'RSRC2021'...
    'RSRC2022'...
    'RSRC2023'...
    'RSRC2024'...
    'RSRC2025'...
    'RSRC2026'...
    'RSRC2027'...
    'RSRC2028'...
    'RSRC2029'...
    };
%    'RSRC2013'... % fire alarm went off during blink period of final test block
%    'RSRC2031'... % did not finish session

  sessions = {'session_0'};

serverDir = '/Volumes/curranlab/Data/RSRC2/eeg/behavioral';
serverLocalDir = '/Volumes/RAID/curranlab/Data/RSRC2/eeg/behavioral';
if exist(serverDir,'dir')
  dataroot = serverDir;
elseif exist(serverLocalDir,'dir')
  dataroot = serverLocalDir;
else
  %uname = getenv('USER');
  uroot = getenv('HOME');
  dataroot = fullfile(uroot,'data/RSRC2/eeg');
end
saveDir = dataroot;
% saveDir = fullfile(dataroot,'events');
% if ~exist(saveDir,'dir')
%   mkdir(saveDir);
% end

eventsOutfile = fullfile(saveDir,'rsrc2_events.mat');

combinedEvents = [];

for sub = 1:length(subjects)
  fprintf('Getting data for %s...',subjects{sub});
  for ses = 1:length(sessions)
    fprintf('%s...',sessions{ses});
    
    % set the subject events directory
    eventsDir_sub = fullfile(dataroot,subjects{sub},sessions{ses},'events');
    events = loadEvents(fullfile(eventsDir_sub,'events.mat'));
    
    % concatenate every subject's events
    combinedEvents = [combinedEvents;events];
  end
  fprintf('Done.\n');
end

fprintf('Saving %d subjects in %s...',length(subjects),eventsOutfile);
% save all subs
saveEvents(combinedEvents,eventsOutfile);
fprintf('Done.\n');

% % fix event fields
% for sub = 1:length(subjects)
%   fprintf('Getting data for %s...',subjects{sub});
%   for ses = 1:length(sessions)
%     fprintf('%s...',sessions{ses});
    
%     events = slork_fixEvents(dataroot,subjects{sub},sessions{ses});
    
%     saveEvents(events,fullfile(dataroot,subjects{sub},sessions{ses},'events','events.mat'));
    
%   end
%   fprintf('Done.\n');
% end

